HAL MDF Typical use cases for migration

This section provides information about the HAL MDF Typical use cases for migration.

The following table analysis highlights some key differences and equivalences between the HAL1 and HAL2 used in the following use cases migration:

Aspect

HAL1

HAL2

Driver implementation

In HAL1, a single driver handles both MDF and ADF peripherals.

In HAL2, the HAL MDF driver has been split into two separate drivers MDF and ADF.

Initialization and configuration

HAL_MDF_Init performs all of the following process in a single call:

  • instance assignment

  • starting clock generator

  • configuring processing clock divider

  • configuring serial interface

  • configuring bitstream matrix, etc.

Functionality split into unitary APIs:

  • HAL_MDF_Init: instance assignment

  • HAL_MDF_SetConfig: configure processing clock divider

  • HAL_MDF_Start: start clock generator

  • HAL_MDF_SITF_SetConfig / HAL_MDF_SITF_Start: configure and start serial interface

  • HAL_MDF_BSMX_SetConfig: configure bitstream matrix, etc.

Sub blocks configuration

MDF and ADF configuration (digital filter, snapshot, discard samples, integrator) performed inside acquisition start APIs (the configuration structure is passed as parameter to acquisition start APIs):

  • HAL_MDF_AcqStart

  • HAL_MDF_AcqStart_IT

  • HAL_MDF_AcqStart_DMA

The configuration moved to dedicated API:

  • HAL_MDF_DFLT_SetConfig

  • HAL_MDF_DFLT_SetSnapshotFormat

  • HAL_MDF_DFLT_SetDiscardSamples

  • HAL_MDF_DFLT_SetIntegrator

MDF use cases

MDF acquisition configuration

this uses case describe the configuration and initialization process before launching acquisition.

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF

== initialization ==
App -> MDF : HAL_MDF_Init()
App <-- MDF : HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* MDF handle declaration */
MDF_HandleTypeDef        MdfHandle0;










/* Initialize the MDF driver handle with the MDF1 instance
   Configure the processing clock divider
   Start MDF clock generator
   Configure and start the serial interface
   Configure the bitstream matrix */
MdfHandle0.Instance = MDF_Filter0;
MdfHandle0.Init.CommonParam.ProcClockDivider = 10;
MdfHandle0.Init.CommonParam.OutputClock.Activation = DISABLE;
MdfHandle0.Init.SerialInterface.Activation = ENABLE;
MdfHandle0.Init.SerialInterface.Mode = MDF_SITF_LF_MASTER_SPI_MODE;
MdfHandle0.Init.SerialInterface.ClockSource = MDF_SITF_CCK0_SOURCE;
MdfHandle0.Init.SerialInterface.Threshold = 4;
MdfHandle0.Init.FilterBistream = MDF_BITSTREAM0_RISING;
HAL_MDF_Init(&MdfHandle0);
/* MDF handle declaration */
hal_mdf_handle_t                  hmdf;
/* Serial interface configuration declaration */
hal_mdf_serial_interface_config_t sitf_config;
/* processing clock divider definition */
#define      PROC_CLK_DIVIDER              10U


/* Initialize the MDF driver handle with the MDF1 instance */
HAL_MDF_Init(&hmdf, HAL_MDF1);

/* configure the processing clock divider */
HAL_MDF_SetConfig(&hmdf, PROC_CLK_DIVIDER);

/* Start MDF clock generator */
HAL_MDF_Start(&hmdf);

/* Configure the serial interface */
HAL_MDF_SITF_SetConfig(&hmdf,
                       HAL_MDF_BLOCK_INDEX_0,  /* serial_interface_index */
                       &sitf_config);

/* Start the serial interface */
HAL_MDF_SITF_Start(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/*  Configure the bitstream matrix */
HAL_MDF_BSMX_SetConfig(&hmdf,
                       HAL_MDF_BLOCK_INDEX_0,     /* bitstream_matrix_index */
                       HAL_MDF_BLOCK_INDEX_0,     /* serial_interface_index */
                       HAL_MDF_BSMX_INPUT_RISING);

MDF acquisition in synchronous continuous/single shot polling mode

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF

== Start acquisition in polling mode ==
App -> MDF : HAL_MDF_AcqStart(&hmdf, &FilterConfig)
App <-- MDF : HAL_OK

App -> MDF : HAL_MDF_GenerateTrgo()
Note over MDF : Enable software trigger output signal
App <-- MDF :HAL_OK

App -> MDF : HAL_MDF_PollForAcq()
Note over MDF : Wait available acquisition
App <-- MDF :HAL_OK
App -> MDF : HAL_MDF_GetAcqValue()
App <-- MDF :Acquisition value

== Stop acquisition in polling mode ==
App -> MDF : HAL_MDF_AcqStop()
App <-- MDF :HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* MDF handle declaration */
MDF_HandleTypeDef        MdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef  FilterConfig;
/* Acquisition variable declaration */
int32_t                  Sample;
/* Timeout definition */
#define                  TIMEOUT        1000

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */


//configure acquisition mode in synchronous continuous mode
//if you want single shot mode, you can set MDF_MODE_SYNC_SINGLE
FilterConfig.AcquisitionMode   = MDF_MODE_SYNC_CONT;

/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

/* Start acquisition
   Configure the digital filter */
HAL_MDF_AcqStart(&MdfHandle0, &FilterConfig);


/* enable software trigger output  */
HAL_MDF_GenerateTrgo(&MdfHandle0);

/* Wait until a value is available */
HAL_MDF_PollForAcq(&MdfHandle0, TIMEOUT);

/* Read acquisition value */
status = HAL_MDF_GetAcqValue(&MdfHandle0, &Sample);

/* Stop acquisition in polling mode */
HAL_MDF_AcqStop(&MdfHandle0);
/* MDF handle declaration */
hal_mdf_handle_t                  hmdf;
/* Digital filter configuration declaration */
hal_mdf_digital_filter_config_t   dflt_config;
/* Acquisition value */
int32_t                           sample;
/* Timeout definition */
#define                           TIMEOUT        1000U

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */


//Configure the digital filter acquisition mode in synchronous continuous mode
//If you want single shot mode, you can set HAL_MDF_DFLT_ACQ_MODE_SYNC_SINGLE
FilterConfig.acquisition_mode   = HAL_MDF_DFLT_ACQ_MODE_SYNC_CONT;

/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

/* Configure the digital filter */
HAL_MDF_DFLT_SetConfig(&hmdf, HAL_MDF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in polling mode */
HAL_MDF_DFLT_StartAcq(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Enable software trigger output */
HAL_MDF_EnableTriggerOutput(&hmdf);

/* Wait until a value is available */
HAL_MDF_DFLT_PollForAcq(&hmdf, HAL_MDF_BLOCK_INDEX_0, TIMEOUT);

/* Read acquisition value */
sample = HAL_MDF_DFLT_GetAcqValue(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Stop acquisition in polling mode */
HAL_MDF_DFLT_StopAcq(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Stop MDF clock generator */
HAL_MDF_Stop(&hmdf);

MDF acquisition in synchronous continuous/single shot interruption mode

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF

== Start acquisition in IT mode ==
App -> MDF : HAL_MDF_AcqStart_IT()
App <-- MDF :HAL_OK

App -> MDF : HAL_MDF_GenerateTrgo()
Note over MDF : Enable software trigger output signal
App <-- MDF :HAL_OK

Note over NVIC : FIFO threshold IT occurrence
NVIC -> MDF : HAL_MDF_IRQHandler()
MDF -> App : HAL_MDF_AcqCpltCallback()
App -> MDF : HAL_MDF_GetAcqValue()
App <-- MDF :Acquisition value
MDF <-- App
NVIC <-- MDF

== Stop acquisition in IT mode ==
App -> MDF : HAL_MDF_AcqStop_IT()
App <-- MDF :HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* MDF handle declaration */
MDF_HandleTypeDef        MdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef  FilterConfig;

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//configure acquisition mode in synchronous continuous mode
//if you want single shot mode, you can set MDF_MODE_SYNC_SINGLE
FilterConfig.AcquisitionMode   = MDF_MODE_SYNC_CONT;
/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/


/* Start acquisition in IT mode
   Configure the digital filter */
HAL_MDF_AcqStart_IT(&MdfHandle0, &FilterConfig);

/* enable software trigger output  */
HAL_MDF_GenerateTrgo(&MdfHandle0);

// Wait until HAL_MDF_AcqCpltCallback is triggered

/* Stop acquisition in IT mode */
HAL_MDF_AcqStop_IT(&MdfHandle0);




/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   int32_t   sample;
   /* Read acquisition value */
   HAL_MDF_GetAcqValue(hmdf, &sample);
 }
/* MDF handle declaration */
hal_mdf_handle_t                  hmdf;
/* Digital filter configuration declaration */
hal_mdf_digital_filter_config_t   dflt_config;

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//Configure the digital filter acquisition mode in synchronous continuous mode
//If you want single shot mode, you can set HAL_MDF_DFLT_ACQ_MODE_SYNC_SINGLE
FilterConfig.acquisition_mode   = HAL_MDF_DFLT_ACQ_MODE_SYNC_CONT;
/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

/* Configure the digital filter */
HAL_MDF_DFLT_SetConfig(&hmdf, HAL_MDF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in interrupt mode */
HAL_MDF_DFLT_StartAcq_IT(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Enable software trigger output */
HAL_MDF_EnableTriggerOutput(&hmdf);

// Wait until HAL_MDF_AcqCpltCallback is triggered

/* Stop acquisition in interrupt mode */
HAL_MDF_DFLT_StopAcq_IT(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Stop MDF clock generator */
HAL_MDF_Stop(&hmdf);

/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   int32_t   sample;
   /* Read acquisition value */
   sample = HAL_MDF_DFLT_GetAcqValue(&hmdf, HAL_MDF_BLOCK_INDEX_0);
 }

MDF acquisition in synchronous continuous/single shot DMA mode

For the DMA process, a new callback HAL_MDF_DFLT_AcqStopCpltCallback has been added and it is triggered when the user calls HAL_MDF_DFLT_StopAcq_DMA API.

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF
participant "DMA" as DMA

== Start acquisition in DMA mode ==
App -> MDF : HAL_MDF_AcqStart_DMA()
App <-- MDF : HAL_OK

App -> MDF : HAL_MDF_GenerateTrgo()
Note over MDF : Enable software trigger output signal
App <-- MDF :HAL_OK

' ---- DMA interrupts during acquisition ----

Note over DMA : Transfer complete interrupt
DMA -> MDF : MDF_DmaXferCpltCallback()
MDF -> App : HAL_MDF_AcqCpltCallback()
Note over App : User implementation
App --> MDF

== Stop acquisition in DMA mode ==
App -> MDF : HAL_MDF_AcqStop_DMA()

' Inside HAL_MDF_AcqStop_DMA, if state == ACQUISITION:
MDF -> DMA : HAL_DMA_Abort()
DMA --> MDF : HAL_OK

App <-- MDF : HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* MDF handle declaration */
MDF_HandleTypeDef       MdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef FilterConfig;
/* DMA handle declaration */
DMA_HandleTypeDef       hdma_mdf;
/* DMA configuration declaration */
MDF_DmaConfigTypeDef    DmaConfig;
 /* Output buffer for DMA */
int32_t mdf_dma_buffer[MDF_DMA_BUFFER_SIZE];

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//configure acquisition mode in synchronous continuous mode
//if you want single shot mode, you can set MDF_MODE_SYNC_SINGLE
FilterConfig.AcquisitionMode   = MDF_MODE_SYNC_CONT;
/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/


/* Start acquisition in DMA mode
   Configure the digital filter */
HAL_MDF_AcqStart_DMA(&MdfHandle0, &FilterConfig, &DmaConfig);

/* enable software trigger output  */
HAL_MDF_GenerateTrgo(&MdfHandle0);

// Wait until HAL_MDF_AcqCpltCallback is triggered

/* Stop acquisition in DMA mode */
HAL_MDF_AcqStop_DMA(&MdfHandle0);




/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   int32_t   sample;
   /* Read acquisition value */
   sample = HAL_MDF_DFLT_GetAcqValue(&hmdf, HAL_MDF_BLOCK_INDEX_0);
 }
/* MDF handle declaration */
hal_mdf_handle_t                  hmdf;
/* Digital filter configuration declaration */
hal_mdf_digital_filter_config_t   dflt_config;







/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//Configure the digital filter acquisition mode in synchronous continuous mode
//If you want single shot mode, you can set HAL_MDF_DFLT_ACQ_MODE_SYNC_SINGLE
FilterConfig.acquisition_mode   = HAL_MDF_DFLT_ACQ_MODE_SYNC_CONT;
/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

/* Configure the digital filter */
HAL_MDF_DFLT_SetConfig(&hmdf, HAL_MDF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in DMA mode */
HAL_MDF_DFLT_StartAcq_DMA(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Enable software trigger output */
HAL_MDF_EnableTriggerOutput(&hmdf);

// Wait until HAL_MDF_AcqCpltCallback is triggered

/* Stop acquisition in DMA mode */
HAL_MDF_DFLT_StopAcq_DMA(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Stop MDF clock generator */
HAL_MDF_Stop(&hmdf);

/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   int32_t   sample;
   /* Read acquisition value */
   sample = HAL_MDF_DFLT_GetAcqValue(&hmdf, HAL_MDF_BLOCK_INDEX_0);
 }

/* callback called when DMA acquisition stop is complete */
void HAL_MDF_DFLT_AcqStopCpltCallback(MDF_HandleTypeDef *hmdf)
{
    //For example, toggle an LED
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}

MDF acquisition in window continuous interruption mode

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF
participant Timer as "Timer"

== initialization ==
App -> MDF : HAL_MDF_Init()
App <-- MDF : HAL_OK

== Start acquisition in IT mode ==
App -> MDF : HAL_MDF_AcqStart_IT()
App <-- MDF :HAL_OK

MDF <-- Timer : Timer output trigger signal


Note over NVIC : FIFO threshold IT occurrence
NVIC -> MDF : HAL_MDF_IRQHandler()
MDF -> App : HAL_MDF_AcqCpltCallback()
App -> MDF : HAL_MDF_GetAcqValue()
App <-- MDF :Acquisition value
MDF <-- App
NVIC <-- MDF

== Stop acquisition in IT mode ==
App -> MDF : HAL_MDF_AcqStop_IT()
App <-- MDF :HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* MDF handle declaration */
MDF_HandleTypeDef        MdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef  FilterConfig;


/* Acquisition value declaration */
int32_t                  sample;
uint8_t                  count = 0;
/* acquisition counter definition */
#define                  ACQ_COUNTER        10U


// Configure output clock to have timer trigger as source for acquisition triggering
MdfHandle0.init.CommonParam.OutputClock.Activation = ENABLE;
MdfHandle0.init.CommonParam.OutputClock.Pins       = MDF_OUTPUT_CLOCK_0;
MdfHandle0.init.CommonParam.OutputClock.Divider    = 2;

MdfHandle0.init.CommonParam.OutputClock.Trigger.Activation = ENABLE;
MdfHandle0.init.CommonParam.OutputClock.Trigger.Source     = MDF_CLOCK_TRIG_TIM1_TRGO;
MdfHandle0.init.CommonParam.OutputClock.Trigger.Edge       = MDF_CLOCK_TRIG_RISING_EDGE;




/* Initialize the MDF driver handle with the MDF instance
   Configure the processing clock divider
   Start MDF clock generator
   Configure and start the serial interface
   Configure the bitstream matrix */
HAL_MDF_Init(&MdfHandle0);

























//configure acquisition mode in window continuous mode
FilterConfig.AcquisitionMode   = MDF_MODE_WINDOW_CONT;
/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/


/* Start acquisition in IT mode
   Configure the digital filter */
HAL_MDF_AcqStart_IT(&MdfHandle0, &FilterConfig);

// Timer output trigger signal

// Wait until HAL_MDF_AcqCpltCallback is triggered

/* Stop acquisition in IT mode */
HAL_MDF_AcqStop_IT(&MdfHandle0);







/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   // increment counter
   count ++;
   /* Read acquisition value */
   HAL_MDF_GetAcqValue(hmdf, &sample);
   if( count == ACQ_COUNTER )
   {
       /* enable trigger output  */
       HAL_MDF_GenerateTrgo(&MdfHandle0);
   }
 }
/* MDF handle declaration */
hal_mdf_handle_t                  hmdf;
/* Digital filter configuration declaration */
hal_mdf_digital_filter_config_t   dflt_config;
/* Serial interface configuration declaration */
hal_mdf_serial_interface_config_t sitf_config;
/* Acquisition value declaration */
int32_t                           sample;
uint8_t                           count = 0;
/* acquisition counter definition */
#define                           ACQ_COUNTER        10U
/* processing clock divider definition */
#define      PROC_CLK_DIVIDER              10U








/* Initialize the MDF driver handle with the MDF instance */
HAL_MDF_Init(&hmdf, HAL_MDF1);

/* configure the processing clock divider */
HAL_MDF_SetConfig(&hmdf, HAL_MDF_BLOCK_INDEX_0, PROC_CLK_DIVIDER);

/* Start MDF clock generator */
HAL_MDF_Start(&hmdf);

/* Configure the serial interface */
HAL_MDF_SITF_SetConfig(&hmdf,
                       HAL_MDF_BLOCK_INDEX_0,  /* serial_interface_index */
                       &sitf_config);

/* Start the serial interface */
HAL_MDF_SITF_Start(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Configure the bitstream matrix */
HAL_MDF_BSMX_SetConfig(&hmdf,
                       HAL_MDF_BLOCK_INDEX_0,     /* bitstream_matrix_index */
                       HAL_MDF_BLOCK_INDEX_0,     /* serial_interface_index */
                       HAL_MDF_BSMX_INPUT_RISING);

// Configure output clock to have timer trigger as source for acquisition triggering
HAL_MDF_SetConfigOutputClock(&hmdf, HAL_MDF_OUTPUT_CLOCK_CCK0, 2U);

HAL_MDF_SetConfigOutputClockTrigger(
    &hmdf,
    HAL_MDF_OUT_CLOCK_TRIG_TIM1_TRGO,   // timer source
    HAL_MDF_OUT_CLOCK_TRIG_RISING_EDGE  // edge
);

HAL_MDF_EnableOutputClockTrigger(&hmdf);
HAL_MDF_EnableOutputClock(&hmdf, HAL_MDF_OUTPUT_CLOCK_CCK0);

//Configure the digital filter acquisition mode in window continuous mode
FilterConfig.acquisition_mode   = HAL_MDF_DFLT_ACQ_MODE_WINDOW_CONT;
/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

/* Configure the digital filter */
HAL_MDF_DFLT_SetConfig(&hmdf, HAL_MDF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in interrupt mode */
HAL_MDF_DFLT_StartAcq_IT(&hmdf, HAL_MDF_BLOCK_INDEX_0);

// Timer output trigger signal

// Wait until HAL_MDF_AcqCpltCallback is triggered

/* Stop acquisition in interrupt mode */
HAL_MDF_DFLT_StopAcq_IT(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Stop the serial interface */
HAL_MDF_SITF_Stop(&hmdf, HAL_MDF_BLOCK_INDEX_0);

/* Stop MDF clock generator */
HAL_MDF_Stop(&hmdf);

/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   // increment counter
   count ++;
   /* Read acquisition value */
   sample = HAL_MDF_DFLT_GetAcqValue(&hmdf, HAL_MDF_BLOCK_INDEX_0);
   if( count == ACQ_COUNTER )
   {
       /* enable trigger output  */
       HAL_MDF_EnableTriggerOutput(&MdfHandle0);
   }
 }

ADF use cases

ADF acquisition with SAD in synchronous continuous/single shot polling mode

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF

== Start acquisition with SAD in polling mode ==
App -> MDF : HAL_MDF_AcqStart()
App <-- MDF : HAL_OK

App -> MDF : HAL_MDF_GenerateTrgo()
Note over MDF : Enable software trigger output signal
App <-- MDF :HAL_OK

App -> MDF : HAL_MDF_PollForAcq()
Note over MDF : Wait available acquisition
App <-- MDF :HAL_OK
App -> MDF : HAL_MDF_GetAcqValue()
App <-- MDF :Acquisition value

App -> MDF : HAL_MDF_PollForSndLvl()
App <-- MDF :HAL_OK

== Stop acquisition with SAD in polling mode ==
App -> MDF : HAL_MDF_AcqStop()
App <-- MDF :HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* ADF handle declaration */
MDF_HandleTypeDef        AdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef  FilterConfig;


/* Acquisition variable declaration */
int32_t                  Sample;
uint32_t                 SoundLevel;
uint32_t                 AmbientNoiseLevel;
/* Timeout definition */
#define                  TIMEOUT        1000

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

 //configure acquisition mode in asynchronous continuous mode
//if you want single shot mode, you can set MDF_MODE_ASYNC_SINGLE
FilterConfig.AcquisitionMode   = MDF_MODE_SYNC_CONT;

// Enable the Sound Activity Detector (SAD)
FilterConfig.SoundActivity.Activation = ENABLE;

/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/







/* Start acquisition
   Configure the digital filter */
HAL_MDF_AcqStart(&AdfHandle0, &FilterConfig);

/* enable software trigger output  */
HAL_MDF_GenerateTrgo(&AdfHandle0);

/* Wait until a value is available */
HAL_MDF_PollForAcq(&AdfHandle0, TIMEOUT);


/* Read acquisition value */
status = HAL_MDF_GetAcqValue(&AdfHandle0, &Sample);

/* Wait for sound level and ambient noise level measurements */
HAL_MDF_PollForSndLvl(&AdfHandle0, TIMEOUT, &SoundLevel, &AmbientNoiseLevel);



/* Stop acquisition */
HAL_MDF_AcqStop(&AdfHandle0);
/* ADF handle declaration */
hal_adf_handle_t                  hadf;
/* Digital filter configuration declaration */
hal_adf_digital_filter_config_t   dflt_config;
/* Serial interface configuration declaration */
hal_adf_sad_config_t              sad_config;
/* Acquisition value */
int32_t                           sample;
uint32_t                 SoundLevel;
uint32_t                 AmbientNoiseLevel;
/* Timeout definition */
#define                           TIMEOUT        1000U

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//Configure the digital filter acquisition mode in asynchronous continuous mode
//If you want single shot mode, you can set HAL_ADF_DFLT_ACQ_MODE_ASYNC_SINGLE
FilterConfig.acquisition_mode   = HAL_ADF_DFLT_ACQ_MODE_ASYNC_CONT;




/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

// configure the Sound Activity Detector (SAD)
HAL_ADF_SAD_SetConfig(&hadf, HAL_ADF_BLOCK_INDEX_0, &sad_config);
// start the Sound Activity Detector
HAL_ADF_SAD_Start(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Configure the digital filter */
HAL_ADF_DFLT_SetConfig(&hadf, HAL_ADF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in polling mode */
HAL_ADF_DFLT_StartAcq(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Enable software trigger output */
HAL_ADF_EnableTriggerOutput(&hadf);

/* Wait until a value is available */
HAL_ADF_DFLT_PollForAcq(&hadf,
                        HAL_ADF_BLOCK_INDEX_0,
                        TIMEOUT);
/* Read acquisition value */
sample = HAL_ADF_DFLT_GetAcqValue(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Wait for sound level and ambient noise level measurements */
HAL_ADF_SAD_PollForSoundLevel(&hadf, HAL_ADF_BLOCK_INDEX_0, TIMEOUT);
/* Read sound level and ambient noise level */
HAL_ADF_SAD_GetSoundAndAmbientNoiseLevels(&hadf, HAL_ADF_BLOCK_INDEX_0, &SoundLevel, &AmbientNoiseLevel);

/* Stop acquisition in polling mode */
HAL_ADF_DFLT_StopAcq(&hadf, HAL_ADF_BLOCK_INDEX_0);

// stop the Sound Activity Detector
HAL_ADF_SAD_Stop(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Stop ADF clock generator */
HAL_ADF_Stop(&hadf);

ADF acquisition with SAD in synchronous continuous/single shot interruption mode

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF

== Start acquisition in IT mode ==
App -> MDF : HAL_MDF_AcqStart_IT()
App <-- MDF :HAL_OK

App -> MDF : HAL_MDF_GenerateTrgo()
Note over MDF : Enable software trigger output signal
App <-- MDF :HAL_OK

Note over NVIC : FIFO threshold IT occurrence
NVIC -> MDF : HAL_MDF_IRQHandler()
MDF -> App : HAL_MDF_AcqCpltCallback()
App -> MDF : HAL_MDF_GetAcqValue()
App <-- MDF :Acquisition value
MDF <-- App
NVIC <-- MDF

Note over NVIC : Sound level ready IT occurrence
NVIC -> MDF : HAL_ADF_IRQHandler()
MDF -> App : HAL_MDF_SndLvlCallback( &mdf, SoundLevel, AmbientNoise)
MDF <-- App :Sound level and ambient noise level
NVIC <-- MDF

== Stop acquisition in IT mode ==
App -> MDF : HAL_MDF_AcqStop_IT()
App <-- MDF :HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* ADF handle declaration */
MDF_HandleTypeDef        AdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef  FilterConfig;


// Acquisition value
int32_t   sample;
// sound level and ambient noise level variables declaration
uint32_t                 SAD_SoundLevel;
uint32_t                 SAD_AmbientNoiseLevel;

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//configure acquisition mode in asynchronous continuous mode
//if you want single shot mode, you can set MDF_MODE_ASYNC_SINGLE
FilterConfig.AcquisitionMode   = MDF_MODE_ASYNC_CONT;

// Enable the Sound Activity Detector (SAD)
FilterConfig.SoundActivity.Activation = ENABLE;

/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/







/* Start acquisition with SAD in IT mode
   Configure the digital filter */
HAL_MDF_AcqStart_IT(&AdfHandle0, &FilterConfig);

/* enable Software trigger output  */
HAL_MDF_GenerateTrgo(&AdfHandle0);

// Wait until HAL_ADF_AcqCpltCallback is triggered

/* Stop acquisition with SAD in IT mode */
HAL_MDF_AcqStop_IT(&AdfHandle0);







/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
   /* Read acquisition value */
   HAL_MDF_GetAcqValue(hmdf, &sample);
 }

 /* callback called when sound level is ready */
void HAL_ADF_SAD_SoundLevelCallback(MDF_HandleTypeDef *hmdf, uint32_t SoundLevel, uint32_t AmbientNoise)
{
   SAD_SoundLevel = SoundLevel;
   SAD_AmbientNoiseLevel = AmbientNoise;
 }
/* ADF handle declaration */
hal_adf_handle_t                  hadf;
/* Digital filter configuration declaration */
hal_adf_digital_filter_config_t   dflt_config;
/* Sound activity detector configuration declaration */
hal_adf_sad_config_t              sad_config;
/* Acquisition value */
int32_t   sample;
// sound level and ambient noise level variables declaration
uint32_t                 SAD_SoundLevel;
uint32_t                 SAD_AmbientNoiseLevel;

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//Configure the digital filter acquisition mode in asynchronous continuous mode
//If you want single shot mode, you can set HAL_ADF_DFLT_ACQ_MODE_ASYNC_SINGLE
FilterConfig.acquisition_mode   = HAL_ADF_DFLT_ACQ_MODE_ASYNC_CONT;




/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

// configure the Sound Activity Detector (SAD)
HAL_ADF_SAD_SetConfig(&hadf, HAL_ADF_BLOCK_INDEX_0, &sad_config);
// start the Sound Activity Detector
HAL_ADF_SAD_Start_IT(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Configure the digital filter */
HAL_ADF_DFLT_SetConfig(&hadf, HAL_ADF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in interrupt mode */
HAL_ADF_DFLT_StartAcq_IT(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Enable software trigger output */
HAL_ADF_EnableTriggerOutput(&hadf);

// Wait until HAL_ADF_AcqCpltCallback is triggered

/* Stop acquisition in interrupt mode */
HAL_ADF_DFLT_StopAcq_IT(&hadf, HAL_ADF_BLOCK_INDEX_0);

// stop the Sound Activity Detector
HAL_ADF_SAD_Stop_IT(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Stop ADF clock generator */
HAL_ADF_Stop(&hadf);

/* callback called when acquisition is complete */
void HAL_ADF_AcqCpltCallback(ADF_HandleTypeDef *hadf)
{
   /* Read acquisition value */
   sample = HAL_ADF_DFLT_GetAcqValue(&hadf, HAL_ADF_BLOCK_INDEX_0);
 }

 /* callback called when sound level is ready */
void HAL_ADF_SAD_SoundLevelCallback(ADF_HandleTypeDef *hadf, hal_adf_block_index_t digital_filter_index)
{
   HAL_ADF_SAD_GetSoundAndAmbientNoiseLevels(&hadf, HAL_ADF_BLOCK_INDEX_0, &SAD_SoundLevel, &SAD_AmbientNoiseLevel);
 }

ADF acquisition with SAD in synchronous continuous/single shot DMA mode

For the DMA process, a new callback HAL_ADF_DFLT_AcqStopCpltCallback has been added and it is triggered when the user calls HAL_ADF_DFLT_StopAcq_DMA API.

Sequence diagram

@startuml

participant App as "User application"
participant "<font color=green><b>HAL MDF</b></font>" as MDF
participant "DMA" as DMA

== Start acquisition in DMA mode ==
App -> MDF : HAL_MDF_AcqStart_DMA()
App <-- MDF : HAL_OK

App -> MDF : HAL_MDF_GenerateTrgo()
Note over MDF : Enable software trigger output signal
App <-- MDF :HAL_OK

' ---- DMA interrupts during acquisition ----

Note over DMA : Transfer complete interrupt
DMA -> MDF : MDF_DmaXferCpltCallback()
MDF -> App : HAL_MDF_AcqCpltCallback()
Note over App : User implementation
App --> MDF

Note over NVIC : Sound level ready IT occurrence
NVIC -> MDF : HAL_ADF_IRQHandler()
MDF -> App : HAL_MDF_SndLvlCallback( &mdf, SoundLevel, AmbientNoise)
MDF <-- App :Sound level and ambient noise level
NVIC <-- MDF

== Stop acquisition in DMA mode ==
App -> MDF : HAL_MDF_AcqStop_DMA()

' Inside HAL_MDF_AcqStop_DMA, if state == ACQUISITION:
MDF -> DMA : HAL_DMA_Abort()
DMA --> MDF : HAL_OK

App <-- MDF : HAL_OK

@enduml

Code snippet

HAL1

HAL2

/* MDF handle declaration */
MDF_HandleTypeDef       AdfHandle0;
/* Digital filter configuration declaration */
MDF_FilterConfigTypeDef FilterConfig;
/* DMA handle declaration */
DMA_HandleTypeDef       hdma_mdf;
/* DMA configuration declaration */
MDF_DmaConfigTypeDef    DmaConfig;
/* Output buffer for DMA */
int32_t mdf_dma_buffer[MDF_DMA_BUFFER_SIZE];
// Acquisition value
int32_t   sample;
// sound level and ambient noise level variables declaration
uint32_t                 SAD_SoundLevel;
uint32_t                 SAD_AmbientNoiseLevel;

 /* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//configure acquisition mode in asynchronous continuous mode
//if you want single shot mode, you can set MDF_MODE_ASYNC_SINGLE
FilterConfig.AcquisitionMode   = MDF_MODE_ASYNC_CONT;

// Enable the Sound Activity Detector (SAD)
FilterConfig.SoundActivity.Activation = ENABLE;

/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/







/* Start acquisition in DMA mode
   Configure the digital filter */
HAL_MDF_AcqStart_DMA(&AdfHandle0, &FilterConfig, &DmaConfig);

/* enable software trigger output  */
HAL_MDF_GenerateTrgo(&AdfHandle0);

// Wait until HAL_ADF_AcqCpltCallback is triggered

/* Stop acquisition in DMA mode */
HAL_MDF_AcqStop_DMA(&AdfHandle0);







/* callback called when acquisition is complete */
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef *hmdf)
{
    int32_t   sample;
    /* Read acquisition value */
    HAL_MDF_GetAcqValue(hmdf, &sample);
}

/* callback called when sound level is ready */
void HAL_ADF_SAD_SoundLevelCallback(MDF_HandleTypeDef *hmdf, uint32_t SoundLevel, uint32_t AmbientNoise)
{
   SAD_SoundLevel = SoundLevel;
   SAD_AmbientNoiseLevel = AmbientNoise;
 }
/* ADF handle declaration */
hal_adf_handle_t                  hadf;
/* Digital filter configuration declaration */
hal_adf_digital_filter_config_t   dflt_config;
/* Sound activity detector configuration declaration */
hal_adf_sad_config_t              sad_config;




// Acquisition value
int32_t   sample;
// sound level and ambient noise level variables declaration
uint32_t                 SAD_SoundLevel;
uint32_t                 SAD_AmbientNoiseLevel;

/* you should initialize the MDF driver handle, start clock generator, configure
   and start the serial interface, configure the bitstream matrix and other sublocks
   configuration before as described in the previous use case "MDF acquisition
   configuration" */

//Configure the digital filter acquisition mode in asynchronous continuous mode
//If you want single shot mode, you can set HAL_ADF_DFLT_ACQ_MODE_ASYNC_SINGLE
FilterConfig.acquisition_mode   = HAL_ADF_DFLT_ACQ_MODE_ASYNC_CONT;




/* Configure the other fields of dflt_config depending on your use case
(data_source, cic_mode, decimation_ratio, gain, trigger ...)*/

// configure the Sound Activity Detector (SAD)
HAL_ADF_SAD_SetConfig(&hadf, HAL_ADF_BLOCK_INDEX_0, &sad_config);
// start the Sound Activity Detector
HAL_ADF_SAD_Start_IT(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Configure the digital filter */
HAL_ADF_DFLT_SetConfig(&hadf, HAL_ADF_BLOCK_INDEX_0, &dflt_config);
/* Start acquisition in DMA mode */
HAL_ADF_DFLT_StartAcq_DMA(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Enable software trigger output */
HAL_ADF_EnableTriggerOutput(&hadf);

// Wait until HAL_ADF_AcqCpltCallback is triggered

/* Stop acquisition in DMA mode */
HAL_ADF_DFLT_StopAcq_DMA(&hadf, HAL_ADF_BLOCK_INDEX_0);

// stop the Sound Activity Detector
HAL_ADF_SAD_Stop_IT(&hadf, HAL_ADF_BLOCK_INDEX_0);

/* Stop MDF clock generator */
HAL_ADF_Stop(&hadf);

/* callback called when acquisition is complete */
void HAL_ADF_AcqCpltCallback(ADF_HandleTypeDef *hadf)
{
   int32_t   sample;
   /* Lire la valeur */
   sample = HAL_ADF_DFLT_GetAcqValue(&hadf, HAL_ADF_BLOCK_INDEX_0);
 }

 /* callback called when sound level is ready */
void HAL_ADF_SAD_SoundLevelCallback(ADF_HandleTypeDef *hadf, hal_adf_block_index_t digital_filter_index)
{
   HAL_ADF_SAD_GetSoundAndAmbientNoiseLevels(&hadf, HAL_ADF_BLOCK_INDEX_0, &SAD_SoundLevel, &SAD_AmbientNoiseLevel);
 }

/* callback called when DMA acquisition stop is complete */
void HAL_ADF_DFLT_AcqStopCpltCallback(ADF_HandleTypeDef *hadf)
{
    //For example, toggle an LED
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}